{% extends "admin.html" %}

{% block title %} admin - compose {% end %}

{% block header %}
admin
{% end %}

{% block body %}
  <div class="aeCompose">
	<form method="post" action="">
	  <input id="cats" type="hidden" name="cats" value="" />
	  <input type="hidden" id="_extra" name="extra" value="" />
	  <div class="row">
		<label>title</label><input type="text" name="title" value="[{{ nowdate }}]" />
	  </div>
	  <div class="row">
		<label>tag</label><div class="tag">
		{% for cat in cats %}
		<span onclick="select_cat(this,'{{ cat['name'] }}')">{{ cat['name'] }}</span>
		{% end %}
		</div>
	  </div>
	  <div class="row">
		<label>excerpt</label><textarea name="excerpt" rows="10" style="clear:right;"></textarea>
	  </div>
	  <div class="row">
		<label><a href="/a/postfile?keepThis=true&TB_iframe=true&height=50&width=400" class="thickbox" >add picture</a></label>
		<div class="tag" id="postfiles">
		</div>
	  </div>
	  <div class="row">
		<label>content</label><textarea id="_content" name="content" rows="30" style="clear:right;"></textarea>
	  </div>
	  <div class="hr">
		<input type="submit" name="submit" value="Publish" /> <input type="submit" name="submit" value="Private" /> <input type="submit" name="submit" value="Draft" />
	  </div>
	  <div class="hr"></div>
	  {{ xsrf_form_html() }}
	</form>
  </div>
{% end %}


{% block initscript %}
function alertFinish(text){
var extra = $("#_extra").val();
if(extra){
extra = extra+";"+text;
}else{
extra = text;
}
$("#_extra").val(extra);
$("#postfiles").append("<img src='/static/upload/postfiles/thumb_"+text+"' style='margin:5px' onclick='insertAtCursor(\""+text+"\")'/>");
tb_remove();
}

function insertAtCursor(myValue) {
var myField = $("#_content")[0];
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+"<!--#"+myValue+"#-->"+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}

{% end %}
